﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
 }
 <div class="layuimini-container">
     <div class="layuimini-main">
         <fieldset class="table-search-fieldset layui-hide" id="searchField">
             <div>
                 <form class="layui-form layui-form-pane" >
                     <div class="layui-form-item">
                         <div class="layui-inline">
                             <label class="layui-form-label required">日期:</label>
                             <div class="layui-input-block">
                                 <select id="time_horizon" name="time_horizon" lay-verify="required">
                                     <option value="1">今天</option>
                                     <option value="2" selected>近7天</option>
                                     <option value="3">近1个月</option>
                                     <option value="4">近2个月</option>
                                 </select>
                             </div>
                         </div>
                         <div class="layui-inline">
                             <label class="layui-form-label">关键字:</label>
                             <div class="layui-input-inline">
                                 <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input">
                             </div>
                         </div>
                         <div class="layui-inline">
                             <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                         </div>
                     </div>
                </form>
             </div>
         </fieldset>
         <script type="text/html" id="toolbarDemo">
             <div class="layui-btn-container" id="toolbar">
                 <button id="NF-print" authorize="yes" class="layui-btn layui-btn-sm data-add-btn" lay-event="print"><i class="layui-icon">&#xe654;</i>打印条码</button>
                 <button id="NF-printp" name="NF-printp" authorize="yes" class="layui-btn layui-btn-sm layui-btn-danger layui-hide" lay-event="printp"><i class="layui-icon">&#xe654;</i>打印流转箱</button>
                 <button id="NF-enabled" name="NF-enabled" authorize class="layui-btn layui-btn-sm layui-btn-warm layui-hide" lay-event="enabled"><i class="fa fa-play-circle"></i>质检完成</button>
                 <button id="NF-details" name="NF-details" authorize class="layui-btn layui-btn-sm layui-btn-normal layui-hide" lay-event="details"> <i class="layui-icon">&#xe60b;</i>查看</button>
             </div>
         </script>
         <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
         <script type="text/html" id="currentTableBar">
             <a id="NF-enabled" authorize class="layui-btn layui-btn-sm layui-btn-warm" lay-event="enabled"><i class="fa fa-play-circle"></i></a>
             <a id="NF-details" authorize class="layui-btn layui-btn-sm layui-btn-normal" lay-event="details"><i class="layui-icon">&#xe60b;</i></a>
         </script>
     
     
     
     </div>
 </div>
 <script>
     layui.use(['jquery', 'form','table','commonTable', 'common','optimizeSelectOption'], function () {
         var $ = layui.jquery,
             form = layui.form,
             table = layui.table,commonTable = layui.commonTable
             common = layui.common;
         //权限控制(js是值传递)
         currentTableBar.innerHTML = common.authorizeButtonNew(currentTableBar.innerHTML);
         toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
         commonTable.rendertable({
             elem: '#currentTableId',
             id: 'currentTableId',
             url: '/QualityManage/NeedCheck/GetGridJson',
             filter: {
                 clearFilter: false,
                 //数据量大，data就不需要了
                 items: ['column', 'condition', 'editCondition', 'excel']
             },
             totalRow: true,
             cols: [[
                 //此处需修改
                 { type: "checkbox", width: 50 },
                 {
                     field: 'F_IsCheck', title: '完成标识', width: 110, sort: true, filter: true,
                     templet: function (d) {
                         if (d.F_IsCheck == true) {
                             return "<span class='layui-btn layui-btn-normal layui-btn-xs'>是</span>";
                         } else {
                             return "<span class='layui-btn layui-btn-warm layui-btn-xs'>否</span>";
                         }
                     }
                 },
                 { field: 'F_TransferBoxCode', title: '流转箱编号', width: 170,sort: true,filter: true },
                 {
                     field: 'F_CheckType', title: '检验类型', width: 110, sort: true, filter: true,
                     templet: function (d) {
                         return top.clients.dataItems["Mes_CheckType"][d.F_CheckType] == null ? "" : top.clients.dataItems["Mes_CheckType"][d.F_CheckType];
                     }
                 },
                 { field: 'F_MaterialCode', title: '料号编号', width: 170,sort: true,filter: true },
                 { field: 'F_MaterialName', title: '料号名称', width: 200,sort: true,filter: true },
                 {
                     field: 'F_MaterialType', title: '料号分类', width: 105, sort: true, filter: true,
                     templet: function (d) {
                         return top.clients.dataItems["Mes_MaterialType"][d.F_MaterialType] == null ? "" : top.clients.dataItems["Mes_MaterialType"][d.F_MaterialType];
                     }
                 },
                 { field: 'F_MaterialBatch', title: '批号', width: 180, sort: true, filter: true, totalRowText: '合计:'},
                 { field: 'F_Num', title: '检验数量', width: 110, sort: true, filter: true, totalRow: true },
                 { field: 'F_ScapNum', title: '报废数量', width: 110, sort: true, filter: true, totalRow: true},
                 { field: 'F_ReturnNum', title: '退回数量', width: 110, sort: true, filter: true, totalRow: true },
                 { field: 'F_OtherNum', title: '可疑数量', width: 110, sort: true, filter: true, totalRow: true},
                 {
                     field: 'F_CreatorTime', title: '创建时间', width: 160, sort: true, filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' }
                 },
                 {
                     field: 'F_FinishTime', title: '检验完成时间', width: 160,
                     templet: function (d) {
                         if (d.F_FinishTime) {
                             var time = new Date(d.F_FinishTime);
                             return time.Format("yyyy-MM-dd hh:mm:ss");
                         }
                         return '';
                     }
                 },
                { title: '操作', width: 130, toolbar: '#currentTableBar', align: "center" }
             ]]
         });
         // 监听搜索操作
         form.on('submit(data-search-btn)', function (data) {
             //执行搜索重载
             commonTable.reloadtable({
                 elem: 'currentTableId',
                 curr: 1,
                 where: { timetype: data.field.time_horizon, keyword: data.field.txt_keyword }
             });
             return false;
         });
         wcLoading.close();
         //行点击事件监听，控制按钮显示
        var oneList = ["NF-details"];//选择1条显示
         var morerList = ["NF-enabled","NF-printp"];//选中1条以上显示
        commonTable.tableRowClick("checkbox", "currentTableFilter", "currentTableId", oneList, morerList);
         //toolbar监听事件
         table.on('toolbar(currentTableFilter)', function (obj) { 
             var data = table.checkStatus('currentTableId').data;
             var id = data.length > 0 ? data[0].F_Id : null;
             if (obj.event === 'details') {
                if (data.length == 0) {
                   common.modalMsg("未选中数据", "warning");
                   return false;
               }
               common.modalOpen({
                   title: "查看界面",
                   url: "/QualityManage/NeedCheck/Details?keyValue=" +  id,
                   width: "780px",
                   height: "650px",
                  btn: []
               });
             }
             else if (obj.event === 'print') {
                 common.modalPrompt(0, "请输入打印数量", function (r, value) {
                     if (r) {
                         common.ajax({
                             url: '/QualityManage/NeedCheck/PrinterForm',
                             type: "POST",
                             dataType: 'json',
                             data: {num: value },
                             async: false,
                             success: function (data) {
                                 var json = {};
                                 json.cmd = "print";
                                 json.requestId = uuid();
                                 json.data = {};
                                 json.data.printIniInfo = {};
                                 json.data.printIniInfo.filePath = window.document.location.origin + top.clients.printTemplates["二维码编号名称模板"];
                                 json.data.printIniInfo.realName = "二维码编号名称模板";
                                 json.data.printIniInfo.printType = 1;
                                 json.data.printIniInfo.printName = "";
                                 json.data.printIniInfo.landscape = true;
                                 json.data.printIniInfo.paperSize = "";
                                 json.data.printIniInfo.duplex = "";
                                 json.data.data = [];
                                 for (var i = 0; i < data.length; i++) {
                                     var temp = {};
                                     temp.barId = data[i];
                                     temp.code = "条码编号";
                                     temp.name = data[i];
                                     json.data.data.push(temp);
                                 }
                                 top.sendWSPush(json);
                                 common.reload('data-search-btn');
                             }
                         });
                     }
                 });
             }
            else if (obj.event === 'printp') {
                if (data.length == 0) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                if (top.websocket == null || top.websocket.readyState == 3) {
                    common.modalMsg("打印服务未开启", "warning");
                    return false;
                }
                common.modalConfirm("注：您确定要打印选中这些数据吗？", function (r) {
                    if (r) {
                        var ids = [];
                        var json = {};
                        json.cmd = "print";
                        json.requestId = uuid();
                        json.data = {};
                        json.data.printIniInfo = {};
                        json.data.printIniInfo.filePath = window.document.location.origin + top.clients.printTemplates["二维码编号名称模板"];
                        json.data.printIniInfo.realName = "二维码编号名称模板";
                        json.data.printIniInfo.printType = 1;
                        json.data.printIniInfo.printName = "";
                        json.data.printIniInfo.landscape = true;
                        json.data.printIniInfo.paperSize = "";
                        json.data.printIniInfo.duplex = "";
                        json.data.data = [];
                        for (var i = 0; i < data.length; i++) {
                            var temp = {};
                            temp.barId = data[i].F_TransferBoxCode;
                            temp.code = data[i].F_MaterialName;
                            temp.name = data[i].F_TransferBoxCode;
                            json.data.data.push(temp);
                        }
                        top.sendWSPush(json);
                    }
                });
             }
             else if (obj.event === 'enabled') {
                 var ids = [];
                 for (var i = 0; i < data.length; i++) {
                     ids.push(data[i].F_Id);
                 }

                 common.submitPost({
                     prompt: "注：您确定要完成这些流转箱的检验吗？",
                     url: "/QualityManage/NeedCheck/EnabledForm",
                     param: { keyValue: ids.join(',') },
                     success: function () {
                         common.reload('data-search-btn');
                     }
                 });
             }
           else if (obj.event === 'TABLE_SEARCH') {
                var _that = $("#searchField");
                if (_that.hasClass("layui-hide")) {
                   _that.removeClass('layui-hide');
                } else {
                   _that.addClass('layui-hide');
                }
           }
           return false;
       });
        //toolrow监听事件
        table.on('tool(currentTableFilter)', function (obj) {
             var id = obj.data.F_Id;
            if (obj.event === 'details') {
               common.modalOpen({
                   title: "查看界面",
                   url: "/QualityManage/NeedCheck/Details?keyValue=" +id,
                   width: "780px",
                   height: "650px",
                  btn: []
               });
            }
            else if (obj.event === 'enabled') {
                common.submitPost({
                    prompt: "注：您确定要完成该流转箱的检验吗？",
                    url: "/QualityManage/NeedCheck/EnabledForm",
                    param: { keyValue: id },
                    success: function () {
                        common.reload('data-search-btn');
                    }
                });
            }
            return false;
        });
   });
</script>
